﻿
using System.Data;
using Core.Library;

namespace DataObject.Ref
{
    public class RefController
    {
        /***************************************
        = Back End
        -------------------------------------- */

        public static void Ref_UpdateByKey(string key, int status)
        {
            RefDAL.Ref_UpdateByKey(key, status);
        }

        public static void Ref_UpdateTextValueByKey(string key, string text)
        {
            RefDAL.Ref_UpdateTextValueByKey(key, text);
        }

        /***************************************
        = Front End
        -------------------------------------- */

        public static string Ref_GetBannerHome()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.BannerHome);
            }

            if (dt != null && dt.Rows.Count > 0)
                return dt.Rows[0][Constants.Table_Ref.TextValue].ToString();
            return null;
        }

        public static string Ref_GetStringEmailClone()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.EmailClone);
            }

            if (dt != null && dt.Rows.Count > 0)
                return dt.Rows[0][Constants.Table_Ref.TextValue].ToString();
            return null;
        }

        public static bool Ref_GetLockCloneStatus()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.LockClone);
            }

            if (dt != null && dt.Rows.Count > 0)
                return ConvertUtility.ConvertTo<int>(dt.Rows[0][Constants.Table_Ref.Status]) == Constants.RefKey.LockOn;
            return false;
        }

        public static bool Ref_GetTimelineDisplayStatus()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.TimelineDisplay);
            }

            if (dt != null && dt.Rows.Count > 0)
                return ConvertUtility.ConvertTo<int>(dt.Rows[0][Constants.Table_Ref.Status]) == Constants.RefKey.LockOn;
            return true;
        }

        public static bool Ref_GetVoteDisplayStatus()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.VoteDisplay);
            }

            if (dt != null && dt.Rows.Count > 0)
                return ConvertUtility.ConvertTo<int>(dt.Rows[0][Constants.Table_Ref.Status]) == Constants.RefKey.LockOn;
            return false;
        }

        public static bool Ref_GetCheatVoteStatus()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.CheatVote);
            }

            if (dt != null && dt.Rows.Count > 0)
                return ConvertUtility.ConvertTo<int>(dt.Rows[0][Constants.Table_Ref.Status]) == Constants.RefKey.LockOn;
            return false;
        }

        public static bool Ref_GetStartContestStatus()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.StartContest);
            }

            if (dt != null && dt.Rows.Count > 0)
                return ConvertUtility.ConvertTo<int>(dt.Rows[0][Constants.Table_Ref.Status]) == Constants.RefKey.LockOn;
            return false;
        }

        public static bool Ref_GetMemberBreakCacheStatus()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.MemberBreakCache);
            }

            if (dt != null && dt.Rows.Count > 0)
                return ConvertUtility.ConvertTo<int>(dt.Rows[0][Constants.Table_Ref.Status]) == Constants.RefKey.LockOn;
            return false;
        }

        public static bool Ref_GetLockVoteStatus()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.LockVote);
            }

            if (dt != null && dt.Rows.Count > 0)
                return ConvertUtility.ConvertTo<int>(dt.Rows[0][Constants.Table_Ref.Status]) == Constants.RefKey.LockOn;
            return false;
        }

        public static int Ref_GetCurrentRound()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.CurrentRound);
            }

            if (dt != null && dt.Rows.Count > 0)
                return ConvertUtility.ConvertTo<int>(dt.Rows[0][Constants.Table_Ref.Status]);
            return 1;
        }

        public static bool Ref_GetLockRegisterStatus()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.LockRegister);
            }

            if (dt != null && dt.Rows.Count > 0)
                return ConvertUtility.ConvertTo<int>(dt.Rows[0][Constants.Table_Ref.Status]) == Constants.RefKey.LockOn;
            return false;
        }

        public static bool Ref_GetLockEditStatus()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.LockEdit);
            }

            if (dt != null && dt.Rows.Count > 0)
                return ConvertUtility.ConvertTo<int>(dt.Rows[0][Constants.Table_Ref.Status]) == Constants.RefKey.LockOn;
            return false;
        }

        public static bool Ref_GetLockUploadStatus()
        {
            DataTable dt = null;
            using (var db = new MainDB())
            {
                dt = db.StoredProcedures.Ref_GetRefByKey(1, Constants.RefKey.LockUpload);
            }

            if (dt != null && dt.Rows.Count > 0)
                return ConvertUtility.ConvertTo<int>(dt.Rows[0][Constants.Table_Ref.Status]) == Constants.RefKey.LockOn;
            return false;
        }
    }
}
